You are here: Home

View Blog

Error - Unable to cast object of type 'WhereEnumerableIterator`1[System.Windows.Controls.MenuItem]'

by Robin Gaschk on Monday, 3 July 2017 3:22 PM
Came across this error when placing a where clause on linq query against an IEnumerable menuitem list to get a menuitem.

Unable to cast object of type 'WhereEnumerableIterator`1[System.Windows.Controls.MenuItem]' to type 'System.Windows.Controls.MenuItem'

Was quite confusing and no real answers on the web. Worked out that my where clause could probable return more than one menuitem entry (even though I know there is only one result) and therefore I needed to add the .first on the end of the linq query and it solved the issue.

Putting this out there in case others need a hint.

Blogs Parent Separator Robin's Blog
Author
Robin Gaschk

The ramblings of a soapbox man